package com.zyf.school.manager.service.impl;

import com.zyf.school.manager.dao.AreaDao;
import com.zyf.school.manager.domain.Area;
import com.zyf.school.manager.service.AreaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AreaServiceImpl implements AreaService {

    @Autowired
    private AreaDao areaDao;

    private List<Area> areaList;

    @Override
    public List<Area> queryByTel(String tel) {
        return areaDao.queryByTel(tel);
    }
    @Override
    public List<Area> queryByParentTel(String tel) {
        areaList = areaDao.queryByParentTel(tel);
        //areaList = this.setList(areaList);
        return areaList;
    }

    @Override
    public void save(Area area) {
        areaDao.insert(area);
    }
    public List<Area> setList(List<Area> list){
        for (int i=0; i<list.size(); i++){
            String parentTel = list.get(i).getParentId();
            if (parentTel!=null || parentTel !=""){
                areaList = areaDao.queryChidren(list.get(i).getParentId());
                list.get(i).setChildren(areaList);
            }
            setList(areaList);
        }
        return list;
    }
}
